﻿package org.xhs.report.common.ui
{
    import baidu.ui.managers.*;
    import baidu.wenku.common.*;
    import baidu.wenku.common.model.*;
    import baidu.wenku.doc.*;
    import com.greensock.*;
    import flash.display.*;
    import flash.events.*;

    public class ScreenButton extends Sprite
    {
        protected var _isNext:Boolean = true;
        protected var _triangleSpt:Sprite;
        protected var _triangleColor:uint = 7368560;
        protected var _alphaSpt:Sprite;
        protected var _bgSpt:Sprite;
        protected var _bgLinecolor:uint = 12369084;
        protected var _bgColor:uint = 15000804;
        protected var _bgAlpha:Number = 0.5;
        protected var _bgNormalHeight:Number = 30;
        protected var _bgFullscreenHeight:Number = 50;
        protected var _bgWidth:Number = 400;
        protected var _bgHeight:Number;
        protected var screenModel:ScreenModel;

        public function ScreenButton(param1:Boolean = true)
        {
            this._bgHeight = this._bgNormalHeight;
            this._isNext = param1;
            this.initModel();
            this.initUI();
            return;
        }// end function

        protected function initModel() : void
        {
            this.screenModel = InstanceManager.createSingletonInstance(ScreenModel);
            this.screenModel.addEventListener(Event.RESIZE, this.screenResize);
            return;
        }// end function

        protected function initUI() : void
        {
            this._alphaSpt = new Sprite();
            this._alphaSpt.graphics.beginFill(16711680, 0);
            this._alphaSpt.graphics.drawRect((-this._bgWidth) / 2, 0, this._bgWidth, this._bgHeight * 2);
            this._alphaSpt.graphics.endFill();
            addChild(this._alphaSpt);
            this._bgSpt = new Sprite();
            this._bgSpt.graphics.lineStyle(1, this._bgLinecolor, 0.5);
            this._bgSpt.graphics.beginFill(this._bgColor, this._bgAlpha);
            this._bgSpt.graphics.drawRect((-this._bgWidth) / 2 / 3, 0, this._bgWidth / 3, this._bgHeight);
            this._bgSpt.graphics.endFill();
            this._bgSpt.y = this._isNext ? (this._alphaSpt.height - this._bgSpt.height) : (0);
            addChild(this._bgSpt);
            this._triangleSpt = new Sprite();
            this._triangleSpt.graphics.beginFill(this._triangleColor, 0.8);
            if (this._isNext)
            {
                this._triangleSpt.graphics.moveTo(-12.5, -6.5);
                this._triangleSpt.graphics.lineTo(12.5, -6.5);
                this._triangleSpt.graphics.lineTo(0, 6.5);
                this._triangleSpt.graphics.lineTo(-12.5, -6.5);
            }
            else
            {
                this._triangleSpt.graphics.moveTo(-12.5, 6.5);
                this._triangleSpt.graphics.lineTo(12.5, 6.5);
                this._triangleSpt.graphics.lineTo(0, -6.5);
                this._triangleSpt.graphics.lineTo(-12.5, 6.5);
            }
            this._triangleSpt.graphics.endFill();
            this._triangleSpt.x = 0;
            this._triangleSpt.y = this._bgSpt.y + this._bgSpt.height / 2;
            addChild(this._triangleSpt);
            alpha = 0;
            buttonMode = true;
            addEventListener(MouseEvent.MOUSE_OVER, this.ScreenButtonOver);
            addEventListener(MouseEvent.MOUSE_OUT, this.ScreenButtonOut);
            this.reset();
            return;
        }// end function

        protected function ScreenButtonOver(event:MouseEvent) : void
        {
            TweenLite.to(this, 0.3, {alpha:1});
            return;
        }// end function

        protected function ScreenButtonOut(event:MouseEvent) : void
        {
            TweenLite.to(this, 0.3, {alpha:0});
            return;
        }// end function

        protected function screenResize(event:Event = null) : void
        {
            this.reset();
            return;
        }// end function

        protected function reset() : void
        {
            this._bgWidth = this.screenModel.stageWidth - Config.DV_WIDTH_RIGHT_SCROLLBAR - DocConfig.DV_WIDTH_LEFT_PADDING;
            this._bgHeight = this.screenModel.isFullscreen ? (this._bgFullscreenHeight) : (this._bgNormalHeight);
            this.setWidth();
            x = (this.screenModel.stageWidth - Config.DV_WIDTH_RIGHT_SCROLLBAR) / 2 - 2;
            y = this._isNext ? (this.screenModel.stageHeight - Config.SB_HEIGHT - height - Config.TB_HEIGHT + 1) : (-1);
            return;
        }// end function

        public function setWidth(param1:Number = 0, param2:Number = 0) : void
        {
            this._bgWidth = param1 ? (param1) : (this._bgWidth);
            this._bgHeight = param2 ? (param2) : (this._bgHeight);
            this._alphaSpt.graphics.clear();
            this._alphaSpt.graphics.beginFill(16711680, 0);
            this._alphaSpt.graphics.drawRect((-this._bgWidth) / 2, 0, this._bgWidth, this._bgHeight * 2);
            this._alphaSpt.graphics.endFill();
            this._bgSpt.graphics.clear();
            this._bgSpt.graphics.lineStyle(1, this._bgLinecolor, 0.5);
            this._bgSpt.graphics.beginFill(this._bgColor, this._bgAlpha);
            this._bgSpt.graphics.drawRect((-this._bgWidth) / 2 / 3, 0, this._bgWidth / 3, this._bgHeight);
            this._bgSpt.graphics.endFill();
            this._bgSpt.y = this._isNext ? (this._alphaSpt.height - this._bgSpt.height) : (0);
            this._triangleSpt.x = 0;
            this._triangleSpt.y = this._bgSpt.y + this._bgSpt.height / 2;
            return;
        }// end function

    }
}
